package com.zm.demo.sc.sb;

import cn.hutool.core.util.IdUtil;
import com.zm.demo.sc.circlereference.CommandLinePrint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zoum
 * @create 2019/10/29 10:59
 */

@ComponentScan(basePackages = {"com.zm.demo.sc.sb"})
@EnableAutoConfiguration
@RestController
public class Application {

    public static void main(String[] args){
        System.out.println("application start.");
        SpringApplication.run(Application.class, args);
        System.out.println("application end.");
    }

    @RequestMapping("/check")
    public CompletionStage<String> check(){
        return CompletableFuture.supplyAsync(() ->{
            return "OK";
        });
    }

    @RequestMapping("/randomTest")
    public String randomTest(){
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            executorService.submit(() -> {
                long s = System.nanoTime();
                System.out.println(IdUtil.simpleUUID());
                System.out.println(System.nanoTime() - s);
                System.out.println("==============================");
            });
        }
        executorService.shutdown();
        return IdUtil.simpleUUID();
    }

    @Bean
    public CommandLinePrint commandLinePrint(){
        return new CommandLinePrint();
    }
}
